package com.aqie.easy.math;

import java.util.Arrays;

/**
 * 628 三个数最大乘积
 */
public class MaximumProduct {
    /**
     * 1, 三目运算 31ms
     * @param nums
     * @return
     */
    public int maximumProduct(int[] nums) {
        Arrays.sort(nums);
        int N = nums.length - 1;
        int NegativeMinus = nums[0] * nums[1] * nums[N];
        int PositiveMinus = nums[N] * nums[N-1] * nums[N-2];
        return NegativeMinus > PositiveMinus ?  NegativeMinus : PositiveMinus;
    }
}
